#pragma once
#include "RBTree_Set_Map.h"
#include <vector>
#include <string>
namespace bit
{
	template <class K, class V>
	class map
	{
		struct Oft
		{
			const K& operator()(const pair<K, V>& data)
			{
				return data.first;
			}
		};	
	public:
		typedef typename RBTreeNode<pair<const K, V>> Node;
		typedef typename RBTree<K, pair<const K, V>, Oft>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, Oft>::const_iterator const_iterator;

		iterator begin()
		{
			return _m.begin();
		}
		iterator end()
		{
			return _m.end();
		}
		const_iterator begin() const
		{
			return _m.begin();
		}
		const_iterator end() const
		{
			return _m.end();
		}

		pair<iterator, bool> insert(const pair<K, V>& data)
		{
			return _m.Insert(data);
		}

		iterator find(const K& data)
		{
			return _m.Find(data);
		}

		V& operator[](const K& key)
		{
			_m.Insert(make_pair(key, V()));
			iterator it = find(key);
			return it->second;
		}
	private:
		RBTree<K, pair<const K, V>, Oft> _m;
	};
	void MapTest()
	{
		map<int, int> m;
		int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
		for (auto e : a)
		{
			m.insert(make_pair(e, e));
		}
		map<int, int>::iterator it = m.begin();
		while (it != m.end())
		{
			cout << it->first << " " << it->second << endl;
			it++;
		}
		cout << endl;

		it = m.find(6);
		cout << it->first << " " << it->second << endl;
		cout << endl;

		map<string, int> mp;
		vector<string> v = { "A", "B", "C", "D", "B", "A", "C", "C", "A", "D" };
		for (auto& e : v)
		{
			mp[e]++;
		}
		map<string, int>::iterator its = mp.begin();
		while (its != mp.end())
		{
			cout << its->first << ": " << its->second << endl;
			its++;
		}
		cout << endl;

	} 
}